﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using DAL;
using System.Collections.Generic;

public partial class Phumuc : System.Web.UI.Page
{
    PHUMUCBLL pmBll = new PHUMUCBLL();
    BAIVIETBLL bvBLL = new BAIVIETBLL();
    List<BAIVIET> listBv = new List<BAIVIET>();
    THANHVIENBLL tvBll = new THANHVIENBLL();
    COMMENTBLL cmeBll = new COMMENTBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["tenthanhvien"] == null) Response.Redirect("LogIn.aspx");
        if (!Page.IsPostBack)
        {
            int maPhumuc = Int32.Parse(Request.QueryString["macm"]);
            taga_newbv.HRef = "TaoBaiViet.aspx?maPhumuc=" + maPhumuc;

            showList();
        }
        
    }

    public void showList() {
        PHUMUC pm = pmBll.getPhumucWithID(Int32.Parse(Request.QueryString["macm"]));
        int itemCount = 0;
        string str = "";

        listBv = bvBLL.getListBaivietForPaging(PagerV2_1.PageSize, PagerV2_1.CurrentIndex, ref itemCount);

        str += "<div class=\"services_box\">"
                + "<div class=\"service_title\">"
                + "<img src=\"images/icon/001_43.ico\" alt=\"\" title=\"\" style=\"padding-left: 10px; padding-top: 12px; float: left;\"/>"
                + "<h2>&nbsp; Phụ mục : "
                + pm.tenphumuc
                + "</h2>"
                + "</div>"
                + "<div class=\"con_bg_top\"></div>"
                + "<div class=\"col_bg\">"
                + "<div class=\"col_grad_bot\">"
                + "<div class=\"col_grad_top\">"
                + "<div style=\"clear: both\">";

        str += "<div class=\"aboutus_bg\">"
                    + "<table>"
                    + "<tr>"
                    + "<td class=\"about_col0\"><div class=\"about_div_default\">TT</div></td>"
                    + "<td class=\"about_col1\"><div class=\"about_div_default\">Phụ mục</div></td>"
                    + "<td class=\"about_col2\"><div class=\"about_div_default\">Người gửi</div></td>"
                    + "<td class=\"about_col3\"><div class=\"about_div_default\">Xem</div></td>"
                    + "<td class=\"about_col4\"><div class=\"about_div_default\">Trả lời</div></td>"
                    + "</tr>";

        str += "<tr>"
            + "<td>Chủ đề khác</td>"
            + "</tr>";

        str += "<tr>"
            + "<td class=\"about_col0\"><div class=\"normal_div_boder\">_</div></td>"
            + "<td class=\"about_col1_thaoluanxong\"><div class=\"normal_div_boder\"><p>"
            + "<a href=\"Phumuc_block.aspx?macm=" + Page.Request["macm"] + "\" style=\"text-decoration:none\">Các bài viết đã thảo luận xong</a>"
            + "</p></div></td>"
            + "</tr>";

        str += "<tr>"
                    + "<td>Các bài viết đang thảo luân</td>"
                    + "</tr>";

        foreach(BAIVIET bv in listBv){
            THANHVIEN tv = tvBll.getThanhvienWithIDBaiviet(bv.mabaiviet);
            int count_comment= cmeBll.getCountOfCommentByIDBaiviet(bv.mabaiviet);

            if (bvBLL.getTinhtrangWithID(bv.mabaiviet) == "UnBlock")
            {
                str += "<tr>"
                            + "<td class=\"about_col0\"><div class=\"normal_div_boder\"></div></td>"
                            + "<td class=\"about_col1\"><div class=\"normal_div_boder\"><p>"
                            + "<a href=\"Baiviet.aspx?mabv=" + bv.mabaiviet + "&tenbv=" + bv.tenbaiviet + "\"runat=\"server\">" + bv.tenbaiviet + "</a>"
                            + "</p></div></td>"
                            + "<td class=\"about_col2\"><div class=\"normal_div_boder\">" + tv.tenthanhvien + "<br/>" + bv.ngaylap.ToShortDateString() + " - " + bv.ngaylap.ToShortTimeString() + "</div></td>"
                            + "<td class=\"about_col3\"><div class=\"normal_div_boder\">" + bv.xem + "</div></td>"
                            + "<td class=\"about_col4\"><div class=\"normal_div_boder\">" + count_comment + "</div></td>"
                            + "</tr>";
            }
        }

        str += "</table>"
                    + "</div>";



        str += "</div>"
        + "</div>"
        + "</div>"
        + "</div>"
        + "<div class=\"con_bg_bot\"></div>"
        + "</div>"
        + "</br>";

        PagerV2_1.ItemCount = itemCount;
        pBaiviet.InnerHtml = str;
    }

    protected void PagerV2_1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        PagerV2_1.CurrentIndex = currnetPageIndx;
        showList();
    }
}
